﻿using System;
using System.Collections;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using AnyOffice.DAL;
using AnyOffice.Components;
using AnyOffice.Model;

namespace AnyOffice.general.news.manage
{
    public partial class re_news : ModulePage
    {
        private void BindData()
        {
            int newsId = Convert.ToInt32(this.ViewState["NewsId"].ToString());
            DataTable table = new NewsCommentDao().SelectByNewsId(base.Conn, newsId);
            if (table.Rows.Count == 0)
            {
                this.litNewsComment.Text = base.ShowMessage("暂无评论");
            }
            else
            {
                this.litNewsComment.Text = "";
                this.rptNewsComment.DataSource = table;
                this.rptNewsComment.DataBind();
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                int newsId = (Request.QueryString["news_id"] == null) ? 0 : int.Parse(Request.QueryString["news_id"].ToString());
                this.ViewState["NewsId"] = newsId;
                DataTable table = new NewsDao().SelectByNewsId(base.Conn, newsId, base.User.Identity.Name);
                if (table.Rows.Count == 0)
                {
                    this.pnlMain.Visible = false;
                    this.litMessage.Text = base.ShowMessage("无新闻记录！");
                    return;
                }
                this.litSubject.Text = table.Rows[0]["Subject"].ToString();
                this.BindData();
            }
            if (this.Page.IsPostBack)
            {
                NewsCommentData data = new NewsCommentData();
                NewsCommentDao dao2 = new NewsCommentDao();
                data.NewsId = Convert.ToInt32(this.ViewState["NewsId"].ToString());
                data.UserId = base.User.Identity.Name;
                data.Content = this.txtContent.Value;
                data.ReplyTime = DateTime.Now;
                dao2.Insert(base.Conn, data);
                this.txtContent.Value = "";
                this.BindData();
            }
        }

 

 

    }
}
